<?php

class Index extends CI_Controller {

    public function __construct() {
        parent::__construct();
    }

    public function index(){
        $this->login();
    }
    
    public function login(){
        if( $this->session->userdata('logged_in') == true || $this->session->userdata('logged_in') == 1 ){
            if( $this->session->userdata('user_role_id') == 1 || $this->session->userdata('user_role_id') == 2 ){
                redirect('admin');
            }
        }
        
        
        if ($_SERVER['REQUEST_METHOD'] == 'POST'){
            $username = $this->input->post('username');
            $password = $this->input->post('password');
            
            $user = $this->myauth->login($username,$password);
            
            if($user){
                redirect('admin');
            }else{
                redirect('index');
            }
        }
        $this->load->view('default/page/login_page');
    }
    
    public function logout(){
        $this->session->unset_userdata('logged_in');
        
        redirect('index');
    }
}